package com.aisile.manager.controller;

import com.aisile.entity.PageResult;
import com.aisile.entity.Result;
import com.aisile.pojo.TbBrand;
import com.aisile.sellergoods.service.BrandService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @标题 BrandController
 * @作者 Mr.chen
 * @创建日期 2018/12/26 15:30
 * @版本号 1.0
 **/
@RestController
@RequestMapping("brand")
public class BrandController {
    @Reference
    BrandService brandService;

    @RequestMapping("findAll")
    public List<TbBrand> findAll(){
        return brandService.findAll();
    }
    @RequestMapping("findPage")
    public PageResult findPage(int page,int rows,@RequestBody TbBrand tbBrand){
        return brandService.findPage(page,rows,tbBrand);
    }
    @RequestMapping("findOne")
    public TbBrand findOne(long id){
        return brandService.findOne(id);
    }
    @RequestMapping("save")
    public Result save(@RequestBody TbBrand tbBrand){
        try {
            brandService.save(tbBrand);
            return new Result(true,"");
        }catch (Exception e){
            return new Result(false,"服务器出现异常");
        }
    }
    @RequestMapping("dele")
    public Result dele(Long [] ids){
        try {
            brandService.dele(ids);
            return new Result(true,"");//controllerAdivce是controller的加强版  ExceptionHandler通用异常处理
        }catch (Exception e){
            return new Result(false,"服务器出现异常");
        }
    }

    @RequestMapping("findBrandList")
    public List<Map> findBrandList(){
        return brandService.findBrandList();
    }
}
